package com.ssm.studen.controller;

import com.ssm.studen.model.Rolepression;
import com.ssm.studen.service.RolePressionService;
import com.ssm.studen.tool.ResponseMessage;
import com.ssm.studen.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 角色人员权限表：
 *              对外提供数据服务接口
 */
@Api(tags = "rolepression")
@RestController
public class RolePressionController {

    @Autowired
    private RolePressionService rolePressionService;


    /*****************角色人员权限表查询********************/
    @ApiOperation("角色人员权限表查询")
    @RequestMapping(value = "/selectRolepression",method = RequestMethod.PUT)
    public ResponseMessage selectRolepression(int rpnum){
        Map<String,List> map = new HashMap<>();
        List<Rolepression> listRoP = rolePressionService.selectRolepression(rpnum);
        map.put("list",listRoP);
        return Result.success("200",map);
    }


    /*****************角色人员权限表更新********************/
    @ApiOperation("角色人员权限表更新")
    @RequestMapping(value = "/updateRolepression",method = RequestMethod.GET)
    public ResponseMessage updateRolepression(Rolepression rolepression){
        //传入的参数不能为空
        if(rolepression != null){
            //参数当中主键不能为0
            if(rolepression.getRpnum() != 0){
                if(rolePressionService.updateRolepression(rolepression) == 1){
                    if(rolepression.getRnum()!=0&&
                            rolepression.getPsnum()!=0&&
                            rolepression.getPnum()!=0){
                        rolePressionService.updateRolepression(rolepression);
                    }
                    return Result.success("更新成功");
                }else{
                    return Result.error("更新失败");
                }
            }
        }
        return Result.error("传入参数不正确");
    }
}
















